/*
 *  七段码
 * */

#include <iostream>

using namespace std;

const int N = 8;
int g[N][N];
int f[N];
bool st[N];
int res;

int Find(int x) {
    return f[x] = f[x] == x ? f[x] : Find(f[x]);
}

void Union(int a, int b) {
    f[Find(a)] = Find(b);
}

void dfs(int n) {
    if (n == 8) {
        for (int i = 1; i <= 7; ++i) f[i] = i;

        for (int i = 1; i <= 7; ++i)
            for (int j = 1; j <= 7; ++j)
                if (st[i] && st[j] && g[i][j]) Union(i, j);

        int x = 0;
        for (int i = 1; i <= 7; ++i)
            if (st[i] && f[i] == i) x++;

        if (x == 1) res++;
        return;
    }

    st[n] = true;
    dfs(n + 1);
    st[n] = false;
    dfs(n + 1);
}

int main() {

    g[1][2] = g[1][6] = 1;
    g[2][1] = g[2][3] = g[2][7] = 1;
    g[3][2] = g[3][4] = g[3][7] = 1;
    g[4][3] = g[4][5] = 1;
    g[5][4] = g[5][6] = g[5][7] = 1;
    g[6][1] = g[6][5] = g[6][7] = 1;
    g[7][2] = g[7][3] = g[7][5] = g[7][6] = 1;

    dfs(1);

    cout << res << endl;
    return 0;
}